import { get } from '../api/get';
const echart = () => import('echarts');
const env = process.env.NODE_ENV;

async function initializeBmap (callback) {
    await echart();
    callback && callback();
}
export async function loadScript (callback) {
    window.initialize_bmap = initializeBmap.bind(this, callback);
    const config = await get('/static/webconfig/config.content.json');
    var script = document.createElement('script');
    const mapkey = env === 'development' ? 'HdhgNVhZ02w6IrkjwOuSYgh1apach3ZY' : config.data.baidumap.token;
    script.src = `https://api.map.baidu.com/api?v=3.0&ak=${mapkey}&callback=initialize_bmap`;
    document.body.appendChild(script);
}
